package com.java.demo.service;

import com.java.demo.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    //1.属性注入
    @Autowired      //DI(依赖注入)
    private UserRepository userRepository;

    public int add() {
        System.out.println("Do UserService add method.");
//        //传统写法
//        UserRepository userRepository = new UserRepository();
//        return userRepository.add();

//        //Spring V1.0
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config");
//        UserRepository userRepository = context.getBean("userRepository",UserRepository.class);
//        return userRepository.add();

        //Spring V2.0
        return userRepository.add();
    }
}
